﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string conStr = "server=.;database=Adimi;uid=sa;pwd=123456";

            var selectStr = "select * from Users";

            var deleteStr = "delete Users where Id = 1012";

            var insertStr = "insert into Users (UserName,Password) values ('ssg',999)";

            var updateStr = "update Users set UserName='bbb' where UserName='bbc' ";

            SqlConnection con = new SqlConnection(conStr);
            
            con.Open();



            SqlCommand delete = new SqlCommand(deleteStr, con);

            var conDelete = delete.ExecuteNonQuery();

            if (conDelete != -1)
            {
                Console.WriteLine("delete成功");
            }



            SqlCommand insert = new SqlCommand(insertStr, con);

            var conInsert = insert.ExecuteNonQuery();

            if (conInsert != -1)
            {
                Console.WriteLine("insert成功");
            }



            SqlCommand update = new SqlCommand(updateStr, con);

            var conUpdate = update.ExecuteNonQuery();

            if (conUpdate != -1)
            {
                Console.WriteLine("update成功");
            }



            SqlCommand select = new SqlCommand(selectStr, con);

            var reader = select.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}\t{3}\t\t\t{4}", "Id", "UserName", "PassWord", "CreaTime", "UptaTime");

            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t\t{2}\t\t{3}\t\t{4}", reader[0], reader[1], reader[2], reader[3], reader[4]);
            }



            con.Close();

        }
    }
}
